// component/topup/topup.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isnavigator:{
      type:Boolean,
      value:false
    },
    
  },
  
  /**
   * 组件的初始数据
   */
  data: {
    voucherslist : [
      {amount : '10', name: '大神快来点击01',date:'2021-07-12'},
      {amount : '20', name: '大神快来点击02',date:'2021-07-12'},
      {amount : '50', name: '大神快来点击03',date:'2021-07-12'},
      {amount : '100', name: '大神快来点击04',date:'2021-07-12'},
      {amount : '200', name: '大神快来点击05',date:'2021-07-12'},
    ],
    amountnum:null,
    idnum:null,
    juanlist:[]
  },

  pageLifetimes: {
    show: function() {
      // 页面被展示
      let _this = this
      let  userInfo =  wx.getStorageSync('userInfo')
      let  token =  wx.getStorageSync('token')
      let mobile = userInfo.mobile
      //获取卷
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
        cmd: 'getVoucherListByMobile',
        mobile:mobile,
        status:1
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (data) {
        let juanlist  = data.data.info.content
        juanlist.forEach((item, index) => {
          item.voucher.giveEndTime =  _this.time( item.voucher.giveEndTime)
          item.voucher.giveStartTime = _this.time(item.voucher.giveStartTime)
          item.voucher.chooseFlag = false
        })
        console.log(juanlist)
        _this.setData({
        juanlist: juanlist
       })
      }
    });

    },
    hide: function() {
      // 页面被隐藏
    },
    resize: function(size) {
      // 页面尺寸变化
    }
  },

  
  /**
   * 组件的方法列表
   */
  methods: {
    /*关闭*/
    isTrue(e){
      let that = this;
      that.setData({
        isnavigator:false
      })
    },
//代金券传值
    ondjq(e){
      console.log(e);
      let that = this;
      let amountnum = e.currentTarget.dataset.amount;
      let idnum = e.currentTarget.dataset.id;
      setTimeout(function(){
        that.setData({
          amountnum,
          idnum,
          isnavigator:false
        })
        that.triggerEvent("vouchersevent",{amountnum,idnum})
      },200)
    },
  
  //时间戳转化时间
  time(data) {
    let that=this
    let tomorrow = new Date(data);
    let year = tomorrow.getFullYear(); //获取年
    let month = tomorrow.getMonth() + 1; //获取月
    let date = tomorrow.getDate(); //获取日
    let tomorrowSS = year + '-' + month + "-" + date       
     return  tomorrowSS
  },
  },

})
